<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use app\models\MGoods;
use app\models\Category;
use yii\helpers\ArrayHelper;
//use yii\jui\DatePicker;
//use kartik\datetime\DateTimePicker;
use kartik\date\DatePicker;


use vova07\imperavi\Widget;

/* @var $this yii\web\View */
/* @var $model app\models\MGoods */
/* @var $form yii\widgets\ActiveForm */


$jsStr = <<< EOF
    $(document).ready(function(){

        function hideGoodsNeworold()
        {
            if($("#mgoods-pub_type").val() == 1)
            {
                $(".field-mgoods-goods_neworold").hide();
            }
            else
            {
                $(".field-mgoods-goods_neworold").show();
            }
        }
        hideGoodsNeworold();
        $("#mgoods-pub_type").change(function(){
            hideGoodsNeworold();
        })
    })

EOF;


$this->registerJs(
    $jsStr,
    yii\web\View::POS_END
);

?>

<div class="mgoods-form" xmlns="http://www.w3.org/1999/html">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>

	<!-- 
    <//?= $form->field($model, 'goods_kind')->dropDownList(MGoods::getGoodsKindOption()) ?>
    -->

	<?= $form->field($model, 'goods_kind')->dropdownList(ArrayHelper::map(Category::find()->where(['parent_id'=>0])->asArray()->all(),'id','name'),
    		[
    			'prompt'=>'请选择一级分类',
    			//'onchange'=>'wx_one(this)',
    			'onchange'=>'

    	            $(".form-group field-mgoods-goods_3rdkind").hide();
            		$.post("'.yii::$app->urlManager->createUrl('goods/category').'&typeid=1&pid="+$(this).val(),function(data){
                	$("select#mgoods-goods_subkind").html(data);
            		});',
             ]);?>

    <!--
    <//?= $form->field($model, 'goods_subkind')->dropdownList(ArrayHelper::map(Category::find()->where(['parent_id'=>$model->goods_kind])->asArray()->all(),'id','name'),
    		[
    			'prompt'=>'选择子分类',	        
       	    ]);?>
    -->

    <?= $form->field($model, 'goods_subkind')->dropdownList(ArrayHelper::map(Category::find()->where(['parent_id'=>$model->goods_kind])->asArray()->all(),'id','name'),
        [
            'prompt'=>'请选择二级分类',
            //'onchange'=>'wx_two(this)',
            'onchange'=>'

                     $(".form-group field-mgoods-goods_3rdkind").hide();
            		$.post("'.yii::$app->urlManager->createUrl('goods/category').'&typeid=2&pid="+$(this).val(),function(data){
                	$("select#mgoods-goods_3rdkind").html(data);
            		});',
        ]); ?>

        <?= $form->field($model, 'goods_3rdkind')->dropdownList(ArrayHelper::map(Category::find()->where(['parent_id'=>$model->goods_subkind])->asArray()->all(),'id','name'),
        [
        'prompt'=>'选择三级分类',
        ]);?>

	<!-- 
    <//?php
        if (Yii::$app->user->identity->role == 1) 
        {
    ?>
        <p><//?= Html::a('新建商品分类', ['goodscat/index']) ?></p>
    <//?php 
        }
    ?>
    -->

    <?= $form->field($model, 'title')->textInput(['maxlength' => 64]) ?>

    <!--
    <//?= $form->field($model, 'brand')->textInput(['maxlength' => 128]) ?>
    -->

    <?= $form->field($model, 'pub_type')->dropDownList(MGoods::getPubTypeOption()) ?>
    <?= $form->field($model, 'goods_neworold')->dropDownList(MGoods::getGoodsNeworoldOption()) ?>

    <!--
    <//?= $form->field($model, 'parameter')->textInput(['maxlength' => 256]) ?>
    -->
    <?php echo $form->field($model, 'parameter')->widget(Widget::className(), [
        'settings' => [
            'lang' => 'zh_cn',
            'minHeight'=>200,
            'maxHeight'=>400,
            'buttonSource'=>false,
            'convertDivs'=>false,
            'removeEmptyTags'=>false,
            'plugins' => [

            ],
        ]
    ]); ?>

    <?= $form->field($model, 'attachment')->textInput(['maxlength' => 256]) ?>

    <?= $form->field($model, 'brand')->dropDownList(MGoods::getBrandOption()) ?>

    <?= $form->field($model, 'model')->textInput(['maxlength' => 128]) ?>

    <?= $form->field($model, 'prod_area')->textInput(['maxlength' => 128]) ?>

    <!--
    <//?= $form->field($model, 'descript')->textInput(['maxlength' => 256]) ?>
    -->

    <!--
    <//?= $form->field($model, 'price_old')->textInput() ?>
    -->

    <!--
    <//?= $form->field($model, 'detail')->textarea(['rows' => 6]) ?>
    -->

    <div class="form-group field-mgoods-purchase_time">
        <?
            // usage without model
            echo '<label>仪表购入时间</label><br><br>';
            echo DatePicker::widget([
                'model' => $model,
                'attribute' => 'purchase_time',
                //'name' => 'MGoods[purchase_time]',
                //'language' => 'zh',
                'options' => ['placeholder' => '仪表购入时间 ...'],
                'pluginOptions' => [
                    'format' => 'mm/dd/yyyy',
                    'autoclose' => true,
                    //'todayBtn' => true,
                    'todayHighlight' => true
                ]
            ]);
        ?>
        <!--
        <span style="color: #ccc;" >也可直接填写。格式：2015-11-18</span>
        -->
        <div class="help-block"></div>
    </div>


    <?= $form->field($model, 'purchase_price')->textInput() ?>
    <?= $form->field($model, 'price')->textInput() ?>

    <!--
    <//?= $form->field($model, 'price_hint')->textInput(['maxlength' => 512]) ?>
    -->

    <?php echo $form->field($model, 'detail')->widget(Widget::className(), [
        'settings' => [
            'lang' => 'zh_cn',
            'minHeight'=>200,
            'maxHeight'=>400,
            'buttonSource'=>true,
            'convertDivs'=>false,
            'removeEmptyTags'=>false,
            'plugins' => [
                'clips',
                'fullscreen',
                'fontcolor',
                'fontfamily',
                'fontsize',
                'limiter',
                'table',
                'textexpander',
                'textdirection',
                'video',
                'definedlinks',
                'filemanager',
                'imagemanager',
            ],
            'imageManagerJson' => Url::to(['/goods/imagesget']),
            'imageUpload' => Url::to(['/goods/imageupload']),
            'fileUpload' => Url::to(['/goods/fileupload']),
        ]
    ]); ?>
    
    <!--
    <//?= $form->field($model, 'list_img_url')->textInput(['maxlength' => 256]) ?>
    -->
    <?= $form->field($model, 'file')->fileInput()->hint('1张商品列表小图，图片建议尺寸：120像素 * 120像素')  ?>

    <!--
    <//?= $form->field($model, 'body_img_url')->textInput(['maxlength' => 512]) ?>
    -->
     <?= $form->field($model, 'files[]')->fileInput(['multiple' => true, 'accept' => 'image/*'])->hint('最多3张商品展示大图，图片建议尺寸：700像素 * 500像素')  ?>


<!--
    <//?= $form->field($model, 'quantity')->textInput() ?>
-->

<!--
    <//?= $form->field($model, 'office_ctrl')->textInput() ?>

    <//?= $form->field($model, 'package_ctrl')->textInput() ?>

    <//?= $form->field($model, 'detail_ctrl')->textInput() ?>

    <//?= $form->field($model, 'pics_ctrl')->textInput() ?>
-->


    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '新增' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
